<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='j' uri='http://java.sun.com/jsp/jstl/core' %> 
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%
	Object obj = application.getAttribute("contextPath");
	if (obj == null) {
		application.setAttribute("contextPath","http://"+request.getServerName() + ":" + request.getServerPort() + ((HttpServletRequest) request).getContextPath());
	}
	pageContext.setAttribute("ctx", request.getContextPath());
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>XXXXXX系統 </title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="${ctx}/js/artDialog/artDialog.js?skin=blue"></script>
<script src="${ctx}/js/artDialog/plugins/iframeTools.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${ctx}/js/md5.js"></script>
<script type="text/javascript" src="${ctx}/js/IPEBG.js"></script>
<link href="${ctx}/css/login2.css" rel="stylesheet" type="text/css" />
<script>
var j = jQuery.noConflict();
var ctx = '${ctx}';
debugger;
if(self!==top) {
	window.location.href = ctx+"/timeout.jsp"
}
(function (config) {
    config['lock'] = true;
    config['fixed'] = true;
    config['okVal'] = 'Ok';
    config['cancelVal'] = 'Cancel';
    // [more..]
})(art.dialog.defaults);

function login(e){
	key=e.keyCode||e.which;
	if(key==13){
        e.returnValuse=false;
        e.cancel = true;
        document.getElementById("loginBtn").click();
	}
}

$(function(){
	errMsg = IPEBG.getQueryString('error');
	if(errMsg!=null){
		alert('Passowrd is incorrect.');
	}
});

var nameFlag = false;
var pswFlag = false;
var codeFlag = false;
function changeVerifyCode(){
	var time=new Date().getTime();
	document.forms[0].verifyCodeImg.src = "${ctx}/login.do?action=changeCode&xx="+time;
}

function checkLoginForm(){
	var username = document.getElementById("j_username").value;
    var pas = document.getElementById("j_password").value; 
    var inputCode = document.getElementById("inputCode").value;
    var flag = false;   
    if(username == null || username == ""){
    	art.dialog.tips('用户名不能为空！', 1.5);
    	document.getElementById("j_username").focus();
    	flag = false;
    }
    if(pas == null || pas == ""){
    	art.dialog.tips('密码不能为空！', 1.5);
    	document.getElementById("j_password").focus();
    	flag = false;
    }
    if(inputCode == null || inputCode == ""){
    	art.dialog.tips('验证码不能为空！', 1.5);
    	document.getElementById("inputCode").focus();
    	flag = false;
    }else{
    	j.ajax({
    		url:'${ctx}/login.do?action=checkVerifyCode&inputCode='+inputCode,
    		date:'',
    		type:'GET',
    		async:false,
    		dateType:'xml',
    		timeout: 100000,
    		error:function(xml){
    			  // alert('响应失败！');
    		   },			
    	    success:function(xml){
    		    var $message = j(xml).find("code").children("stat").text();		    
    			if($message != 'ok'){
    				art.dialog.tips('验证码不正确！', 1.5);
    				flag = false;
    			}else{
    				codeFlag = true;
    				flag = true;
    			}
    		}
    	});
    }
    if(flag == true){
		var psd= document.getElementById("j_password").value;
		var md5psd=calcMD5(psd);
		//alert(md5psd);
		j("#j_password").val(md5psd);
    	document.forms[0].submit();
		return true;
    }
    return flag;
}
function checkLoginCode(){
	codeFlag = false;
	var inputCode = document.getElementById("inputCode").value;
	if(inputCode==null || inputCode==""){
		return false;
	}
	j.ajax({
		url:'${ctx}/login.do?action=checkVerifyCode&inputCode='+inputCode,
		date:'',
		type:'GET',
		dateType:'xml',
		timeout: 100000,
		error:function(xml){
			  // alert('响应失败！');
		   },			
	    success:function(xml){
		    var $message = j(xml).find("code").children("stat").text();		    
			if($message != 'ok'){
				art.dialog.tips('验证码不正确！', 1.5);
				return false;
			}else{
				codeFlag = true;
			}	
		   }
		});
}
</script>
</head>
<body>
<h1>XXXXXX系統</h1>
<div class="login" style="margin-top:50px;" id="login" onkeydown="login(event);">
    <div class="header">
        <div class="switch" id="switch">
			<a class="switch_btn_focus" id="switch_qlogin" href="javascript:void(0);" tabindex="7">用戶登錄</a>
			<div class="switch_bottom" id="switch_bottom" style="position: absolute; width: 66px; left: 0px;"></div>
        </div>
    </div>
    <div class="web_qr_login" id="web_qr_login" style="display: block; height: 280px;">
	<!--登录-->
	<form name="loginForm" action="<c:url value='/j_spring_security_check'/>" method="post" >
	<j:if test="${not empty param.login_error}">
		<script type="text/javascript">
			art.dialog.tips('用户或密码不对，请重新输入！', 3);
		</script>
	</j:if> 
		<div class="web_login" id="web_login">
			<div class="login-box">
				<div class="login_form">
					<div class="uinArea" id="uinArea">
						<label class="input-tips" for="j_username">用戶名：</label>
						<div class="inputOuter" id="uArea">
							<input type="text" name="j_username"  id="j_username" value="" autocomplete="off" class="inputstyle"/>
						</div>
					</div>
					<div class="pwdArea" id="pwdArea">
						<label class="input-tips" for="j_password">密&nbsp;&nbsp;&nbsp;&nbsp;碼：</label>
						<div class="inputOuter" id="pArea">
							<input type="password" name="j_password"  id="j_password" value="" autocomplete="off" class="inputstyle"/>
						</div>
					</div>
					<div class="codeArea" id="codeArea">
						<label class="input-tips" for="inputCode" style="margin-top:10px;">驗證碼：</label>
						<div class="codeOuter" id="pArea">
							<input type="text" id="inputCode" name="code" class="codeinput" onblur="checkLoginCode(this);" autocomplete="off"/>
							<img name="verifyCodeImg" src="${ctx}/login.do?action=changeCode" style="cursor: hand; position:relative; top:12px;" width="60" height="35" alt="看不清，点击换一张" onclick="changeVerifyCode();" />
							<a href="javascript:changeVerifyCode();" onclick="changeVerifyCode();">看不清，換一張</a></li>
						</div>
					</div>
					<div style="padding-left:100px;margin-top:20px;height:41px;"><input id="loginBtn" type="button" onclick="checkLoginForm()" value="登 錄" style="width:150px;" class="button_blue"/></div>
					<!-- <div class="jianyi">* 請使用一賬通賬號和密碼登錄本平台 *</div> -->
			   </div>
            </div>
               
		</div>
    <!--登录end-->
    </form>
  </div>
</div>
<div class="copyright">Copyright © iPEBG-中原資訊服務處-系統開發中心 版權所有</div>
<script type="text/javascript">

</script>
</body>
</html>